<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
		</script>

		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="">系统首页</a>
			</li>
			<li class="active">
				设备管理
			</li>
            <li class="active">
				设备续费
			</li>
		</ul><!-- .breadcrumb -->
	</div>
	<div class="page-content">
	<!-- /.page-header -->
	   <div class="row">
	   <div  class="page-header" >
	       <h1>设备续费</h1>
	   </div>
	   <form class="form-table" action="<?php echo base_url().'admin/device/edit_device_price/'.$device->id;?>" method="post" id="usrform" role="form">
	   <input type="hidden" name="id" value="<?php if (isset($device->id))echo $device->id;?>">
	   <input type="hidden" name="user_id" value="<?php if (isset($device->user_id))echo $device->user_id;?>">
	   <input type="hidden" name="end_date" value="<?php if (isset($device->end_date))echo $device->end_date;?>">
	       <?php if (isset($message)&&$message!=''){?>
	       <div id="info_msg" class="alert alert-success"><?php echo $message;?></div>
	       <?php }?>
	       <?php if (validation_errors()!=''){?>
	       <div id="info_msg" class="alert alert-danger"><?php echo validation_errors();?></div>
	       <?php }?>
	       <div class="col-xs-12 margin_t margin_b">
				<div class="table-responsive  tab" id="facility">
					<table id="sample-table-1" class="table table-striped table-bordered table-hover">
                    	<tr>
                        	<td>
                            	<p>用户账号：</p>
                            </td>
                            <td>
                                <?php if (isset($device->phone))echo $device->phone;?>
                            </td>
                            <td>
                            	<p>姓名：</p>
                            </td>
                            <td>
                                <?php if (isset($device->user_name))echo $device->user_name;?>
                            </td>
                            <td>
                            	<p>身份证号：</p>
                            </td>
                            <td>
                            	<?php if (isset($device->cardno))echo substr($device->cardno, 0,strlen($device->cardno)-4)."****";?>
                            </td>
                        </tr>
                        <tr>
                        	<td><P>设备大类：</P></td>
                            <td>
                            	<?php if (isset($device->category_name))echo $device->category_name;?>
                            </td>
                            <td><P>设备类型：</P></td>
                            <td>
                            	<?php if (isset($device->type_name))echo $device->type_name;?>
                            </td>
                            <td><P>设备型号：</P></td>
                            <td>
                            	<?php if (isset($device->model_name))echo $device->model_name;?>
                            </td>
                            
                            </tr>
                            <tr>
                            	<td><P><span style="color: red;">*</span>设备标示ID：</P></td>
                                <td class="form-group">
                                    <input type="text" class="col-xs-9" name="device_id" value="<?php if (isset($device->device_id))echo $device->device_id;?>"  check-type="required" placeholder="输入 ..."/>
                                </td>
                                <td><P>SIM卡号：</P></td>
                                <td>
                                    <?php if (isset($device->sim_id))echo $device->sim_id;?>
                                </td>
                                <td><P><span style="color: red;">*</span>发放方式:</P></td>
                                <td class="form-group">
                                	<label for="buy"><input id="buy" type="radio" name="out_type" value="1" <?php if (isset($device->out_type)&&$device->out_type == 1)echo "checked"?>/>购买</label>
                                    <label for="free"><input id="free" type="radio" name="out_type" value="2" <?php if (isset($device->out_type)&&$device->out_type == 2)echo "checked"?>/>免费</label>
                                </td>
                            </tr>
                                <tr>
                                	
                                    <td><P><span style="color: red;">*</span>设备价格：</P></td>
                                    <td class="form-group">
                                    	<input type="text"  class="col-xs-9" name="price" value="<?php if (isset($device->price))echo $device->price;?>" check-type="required number" placeholder="输入 ..."/>
                                        <label>元</label>
                                    </td>
                                    <td><P><span style="color: red;">*</span>服务费用：</P></td>
                                    <td class="form-group">
                                    	<input type="text" class="col-xs-9" name="service_price" value="<?php if (isset($device->service_price))echo $device->service_price;?>" check-type="required number" placeholder="输入 ..."/>
                                        <label>元</label>
                                    </td>
                                    <td><p><span style="color: red;">*</span>服务套餐</p></td>
                                	<td class="form-group">
                                		<select class="col-xs-9" id="service_package" name="service_package" check-type="required" onchange="show_package()">
		                                	<option value="">未设置</option>
		                                	<?php if (isset($service_package)&&count($service_package)>0){
                                            foreach ($service_package as $v){?>
                                                   <option value="<?php echo $v->id;?>" <?php if (isset($device->service_package)&&$device->service_package == $v->id)echo "selected"?>><?php echo $v->name;?></option>
                                                <?php }
                                            }?>
		                                </select>
                                	</td>
                                </tr>
                                <tr>
                                	
                                	<td><p><span style="color: red;">*</span>是否付款:</p></td>
                                	<td>
                                		<label for="yes"><input id="yes" type="radio" name="is_pay" value="1" <?php if (isset($device->is_pay)&&$device->is_pay == 1)echo "checked"?>/>已付</label>
                                        <label for="no"><input id="no" type="radio" name="is_pay" value="2" <?php if (isset($device->is_pay)&&$device->is_pay == 2)echo "checked"?>/>未付</label>
                                	</td>
                                	<td><p>销售人员</p></td>
                                	<td>
                                	<input type="hidden" name="seller_id" value="<?php if (isset($device->seller_id))echo $device->seller_id;?>" >
                                		<?php if (isset($seller)){echo $seller->user_phone.'('.$seller->user_name.')';}?>
                                	</td>
                                	<td><p>服务专员</p></td>
                                	<td>
                                	    <?php if (isset($service_admin))echo $service_admin->user_phone.'('.$service_admin->user_name.')';?>
                                	</td>
                                </tr>
							</table>
						</div>
						<div id="package">
					       <div class="page-header">
					           <h4>套餐详情</h4>
					       </div>
					       <label>包含服务内容：</label><br>
					       <p>
					           <?php if (isset($package)&&count($package)>0){
					           foreach ($package as $val){
					               ?>
					               <span><?php echo $val->tname.'--'.$val->oname.'--'.$val->num;?><?php if ($val->charging_type == 0){echo '无';}elseif ($val->charging_type == 1){echo '次';}elseif ($val->charging_type == 2){echo '小时';}elseif ($val->charging_type == 3){echo '台';}elseif ($val->charging_type == 4){echo '年';}?></span><br>
					           <?php }
					           }?>
					       </p>
						</div>
					</div>
					<div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button class="btn btn-info" id="btnSubmit" type="submit">
								<i class="icon-ok bigger-110"></i>
								保存
							</button>
							&nbsp; &nbsp; &nbsp; <a class="btn"
								href="<?php echo base_url()."admin/device/device_list"?>"> <i
								class="icon-undo bigger-110"></i> 返回
							</a>
						</div>
					</div>
            </form>
		</div><!-- /.row -->
	</div><!-- /.page-content -->
</div><!-- /.main-content -->
	<script type="text/javascript">
	$("#usrform").validation();
	$(".chosen-select").chosen(); 
	//保存
	$("#btnSubmit").on('click',function(event){
	  // 2.最后要调用 valid()方法。
	  if ($("#usrform").valid()==false){
	    return false;
	  }
	});
	function show_package(){
		var vs = $('#service_package option:selected').val();
		$.ajax( {
	        url:"<?php echo base_url().'admin/device/get_package';?>",
	        data:{pid:vs},
	        type:'post',
	        cache:false,
	        dataType:'json',    
	        success:function(data) {
	        	var content = '<div class="page-header">';
	        	content = content + '<h4>套餐详情</h4>';
	        	content = content + '</div>';
	        	content = content + '<label>包含服务内容：</label><br>';
	        	content = content + '<p>';
	        	for(var i=0;i<data['package'].length;i++){
    	        	content = content + '<span>'+data['package'][i].tname+'--';
    	        	content = content + data['package'][i].oname+'--';
    	        	content = content + data['package'][i].num;
    	        	if(data['package'][i].charging_type == '1'){
    	        		content = content + '次';
    	        	}else if(data['package'][i].charging_type == '2'){
    	        		content = content + '小时';
    	        	}else if(data['package'][i].charging_type == '3'){
    	        		content = content + '台';
    	        	}else if(data['package'][i].charging_type == '4'){
    	        		content = content + '年';
    	        	}else if(data['package'][i].charging_type == '0'){
    	        		content = content + '无';
    	        	}else{
    	        		content = content + '';
    	        	}
    	        	content = content + '</span><br>';
	        	}
	        	content = content + '</p>';
	        	$('#package').html(content);
	        },
	        error : function() {       
	            alert("error");
	        }
		});
	}
	</script>